package com.hspedu.newData.dmsxl.数组.模拟;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-09 
 * @Version: 1.0
 */

public class LC36有效的数独 {

    public boolean isValidSudoku(char[][] board) {

        int[][] rows = new int[9][9];
        int[][] cols = new int[9][9];
        int[][][] subboxes = new int[3][3][9];

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.'){
                    continue;
                }
                int index = board[i][j] - '1';
                rows[i][index]++;
                cols[j][index]++;
                subboxes[i/3][j/3][index]++;

                if (rows[i][index] > 1 || cols[j][index] > 1 ||
                subboxes[i/3][j/3][index] > 1){
                    return false;
                }
            }
        }

        return true;
    }

}
